#============================================================
#	PlayerBaseStateState
#============================================================
# * 这是这个状态机的基础状态类，默认添加到场景中，便于修改这个类型中的属性
#     和方法。
#============================================================
# @datetime: 2022-5-1 22:35:53
#============================================================
class_name PlayerBaseState
extends BaseExecuteState


onready var InputKey : PlayerStateBlackboard._InputKey = get_blackboard().InputKey


#============================================================
#   Set/Get
#============================================================
#(override)
func get_blackboard() -> PlayerStateBlackboard:
	return .get_blackboard() as PlayerStateBlackboard

#(override)
func get_host() -> Player:
	return owner as Player


#============================================================
#   自定义
#============================================================
##  移动
func input_move() -> bool:
	var direction = Input.get_axis(InputKey.LEFT, InputKey.RIGHT)
	if direction and get_blackboard().is_can_move():
		get_blackboard().controller.move(direction)
		return true
	return false


##  跳跃
func input_jump() -> bool:
	if (Input.is_action_pressed(InputKey.UP)
		and get_blackboard().is_can_jump()
	):
		if get_blackboard().controller.jump():
			return true
	return false


##  下落
func input_fall() -> bool:
	if (Input.is_action_pressed(InputKey.DOWN)
		and get_blackboard().is_can_fall()
	):
		get_blackboard().controller.fall()
		return true
	return false


##  发出攻击
func input_attack() -> bool:
	if (Input.is_action_pressed(InputKey.ATTACK)
		and get_blackboard().is_can_attack()
	):
		get_blackboard().attack_wrapper.attack()
		return true
	return false


##  爬墙
func input_climb_wall():
	if (get_blackboard().is_can_climb_wall()
		and Input.is_action_pressed(InputKey.UP)
	):
		# 一跳一跳的爬墙
		get_blackboard().get_move_controller().jump(
			# 爬墙速度为 jump_height 的 0.6
			0.6 * get_blackboard().get_property('jump_height')
			, true
		)
		return true
	return false


##  爬楼梯
func input_climb_stairs():
	if get_blackboard().is_can_climb_staris():
		var velocity = Input.get_vector(
			InputKey.LEFT,
			InputKey.RIGHT,
			InputKey.UP,
			InputKey.DOWN
		)
		if velocity != Vector2.ZERO:
			get_blackboard().controller.move(velocity.x)
			get_host().move_and_slide(Vector2(
				0, velocity.y * get_blackboard().get_property("move_speed")
			))
		return true
	return false



